//
//  PigPayFooterView.m
//  PigMarket
//
//  Created by mac on 2019/4/9.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "PigPayFooterView.h"

@implementation PigPayFooterView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.title];
    [self addSubview:self.priceLab];
    [self addSubview:self.discountsLab];
    [self addSubview:self.confirmBtn];
}

- (void)initLayout {
    // 布局子控件
    [self.confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(126, 54));
    }];

    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(18);
        make.width.mas_equalTo(60);
    }];
    [self.discountsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.title.mas_bottom).offset(6);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(self.confirmBtn.mas_left).offset(-10);
    }];
    [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.title.mas_right).offset(6);
        make.centerY.mas_equalTo(self.title.mas_centerY);
        make.right.mas_equalTo(self.confirmBtn.mas_left).offset(-10);
    }];
}

#pragma mark - getter and setter
- (void)setInfoDic:(NSDictionary *)infoDic {
    self.title.text = infoDic[@"title"];
    if ([infoDic[@"discount"] length] > 0) {
        self.discountsLab.text = infoDic[@"discount"];
    }else {
        self.discountsLab.hidden = YES;
        [self.title mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.mas_centerY);
            make.left.mas_equalTo(15);
            make.height.mas_equalTo(18);
            make.width.mas_equalTo(60);
        }];
    
    }
    [self.confirmBtn setTitle:infoDic[@"confirmTitle"] forState:UIControlStateNormal];
}
- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = [UIColor textBlackColor];
        _title.font = [UIFont systemFontOfSize:13];
    }
    return _title;
}
- (UILabel *)priceLab {
    if (!_priceLab) {
        _priceLab = [[UILabel alloc] init];
        _priceLab.textColor = [UIColor colorWithHexString:@"#F25C62"];
        _priceLab.font = [UIFont largerFont];
        
    }
    return _priceLab;
}
- (UILabel *)discountsLab {
    if (!_discountsLab) {
        _discountsLab = [[UILabel alloc] init];
        _discountsLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _discountsLab.font = [UIFont smallFont];
    }
    return _discountsLab;
}
- (UIButton *)confirmBtn {
    if (!_confirmBtn) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        [_confirmBtn setBackgroundImage:[UIImage imageNamed:@"adopt_adoptdetail_confirm"] forState:UIControlStateNormal];
    }
    return _confirmBtn;
}

@end

#pragma mark ---------------- 详情尾视图---------------------------
@implementation PigDetailFooterView

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.confirmAgreementBtn];
    [self addSubview:self.freeAdoptBtn];
    [self addSubview:self.orderBtn];
    [self addSubview:self.adoptBtn];
}

- (void)initLayout {
    // 布局子控件
    [self.confirmAgreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(10);
        make.height.mas_equalTo(20);
    }];
    [self.orderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.confirmAgreementBtn.mas_bottom).offset(20);
        make.centerX.mas_equalTo(self.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH/3, 54));
        make.height.mas_equalTo(54);
    }];
    [self.freeAdoptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.orderBtn.mas_centerY);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(self.orderBtn.mas_left).offset(0);
        make.height.mas_equalTo(54);
    }];
    [self.adoptBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.orderBtn.mas_centerY);
        make.left.mas_equalTo(self.orderBtn.mas_right).offset(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(54);
    }];
}
- (void)confirmAgreementTapped:(UIButton *)button {
    button.selected = !button.selected;
}
//修改图片位移
- (void)setBtnImgEdge:(UIButton *)button {
    [button setTitleEdgeInsets:UIEdgeInsetsMake(0, 4, 0, -4)];
    
}
#pragma mark - getter and setter
- (UIButton *)confirmAgreementBtn {
    if (!_confirmAgreementBtn) {
        _confirmAgreementBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmAgreementBtn setTitle:@"我已阅读并同意领养协议" forState:UIControlStateNormal];
        [_confirmAgreementBtn setTitleColor:[UIColor tipsGrayColor] forState:UIControlStateNormal];
        _confirmAgreementBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [_confirmAgreementBtn setImage:[UIImage imageNamed:@"adopt_adoptdetail_agreement"] forState:UIControlStateNormal];
        [_confirmAgreementBtn setImage:[UIImage imageNamed:@"adopt_adoptdetail_agreement_selected"] forState:UIControlStateSelected];
        [_confirmAgreementBtn addTarget:self action:@selector(confirmAgreementTapped:) forControlEvents:UIControlEventTouchUpInside];
        [self setBtnImgEdge:_confirmAgreementBtn];
    }
    return _confirmAgreementBtn;
}
- (UIButton *)freeAdoptBtn {
    if (!_freeAdoptBtn) {
        _freeAdoptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _freeAdoptBtn.backgroundColor = [UIColor whiteColor];
        [_freeAdoptBtn setTitle:@"免费试养" forState:UIControlStateNormal];
        [_freeAdoptBtn setTitleColor:[UIColor textBlackColor] forState:UIControlStateNormal];
        _freeAdoptBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_freeAdoptBtn setImage:[UIImage imageNamed:@"adopt_adoptdetail_free"] forState:UIControlStateNormal];
        [self setBtnImgEdge:_freeAdoptBtn];

    }
    return _freeAdoptBtn;
}
- (UIButton *)orderBtn {
    if (!_orderBtn) {
        _orderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _orderBtn.backgroundColor = [UIColor whiteColor];
        [_orderBtn setTitle:@"99元预定" forState:UIControlStateNormal];
        [_orderBtn setTitleColor:[UIColor textBlackColor] forState:UIControlStateNormal];
        _orderBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        [_orderBtn setImage:[UIImage imageNamed:@"adopt_adoptdetail_order"] forState:UIControlStateNormal];
        [self setBtnImgEdge:_orderBtn];

    }
    return _orderBtn;
}
- (UIButton *)adoptBtn {
    if (!_adoptBtn) {
        _adoptBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_adoptBtn setTitle:@"立即领养" forState:UIControlStateNormal];
        [_adoptBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _adoptBtn.titleLabel.font = [UIFont systemFontOfSize:17];
        [_adoptBtn setBackgroundImage:[UIImage imageNamed:@"adopt_adoptdetail_confirm"] forState:UIControlStateNormal];
    }
    return _adoptBtn;
}


@end
